package com.ixuestar.util;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import javax.imageio.ImageIO;
import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.BodyPart;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.internet.MimeMessage;

import com.sun.mail.imap.IMAPStore;

import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;


public class Test {
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		
//		try {
			
			
//			InputStream fileInputStream = new FileInputStream(new File("D:\\Program Files\\Desktop\\new24.json"));
//			BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
//			
//			StringBuffer stringBuffer = new StringBuffer();
//			String lineStringBuffer="";
//			while((lineStringBuffer=bufferedReader.readLine())!=null) {
//				stringBuffer.append(lineStringBuffer);
//			}
//			List<String> list = new LinkedList<>();
//			JSONArray parseArray = JSONObject.parseObject(stringBuffer.toString()).getJSONObject("data").getJSONArray("recordList");
//			String string="";
//			for (int i = 0; i < parseArray.size(); i++) {
//				JSONObject jsonObject = parseArray.getJSONObject(i);
//				
////				if (string.equals("")) {
////					string = jsonObject.getString("id");
////				}else {
////					string = string + "," + jsonObject.getString("resId");
////				}
//				System.out.println(jsonObject.getString("cshipcode"));
//			}
//			
			
//			String string = "本次业务属于跨组织销售内部交易（双方会计主体不同），调出会计主体：1000-国吉祥(三亚市吉阳区)企业管理有限公司，调入会计主体：贵州仁怀国吉祥酒业有限责任公司。要保证本次业务成功需先做如下设置：\\r\\n1、内部交易规则，约定结算币种和取价规则等  \\r\\n2、将调出、调入会计主体分别设置为内部供应商、客户 \\r\\n3、设置内部交易结算价格。\\r\\n详见内部交易帮助“场景展示-关键设置”和“初始准备”。\\r\\n当前错误为：\\r\\n物料[国吉祥牌 纪念版1949系列酱香酒 53度 500ml 规格1×500ml 一箱6瓶装(1000003)-1×500ml-53度],未取到内部交易价格";
//			string = string.substring(string.indexOf("当前错误为")+6);
//			System.out.println(string);
			
			
			
//			Iterator<String> iterator = parse.keySet().iterator();
//			while (iterator.hasNext()) {
//				String next = iterator.next();
//				Object object = parse.get(next);
//				int array = isArray(object);
//				if (array==0) {
//					String string = ""+next+"\t"+"string"+"\t"+object==null?"":object.toString();
//					System.out.println(string);
//				}else if (array==1) {
//					JSONObject jsonObject = parse.getJSONObject(next);
//					System.out.println(next+"\t"+"object"+"\t"+" ");
//					Iterator<String> iterator2 = jsonObject.keySet().iterator();
//					while (iterator2.hasNext()) {
//						String next1 = iterator2.next();
//						Object object1 = jsonObject.get(next1);
//						System.out.println(next1+"\t"+"string"+"\t"+object1==null?"":object1.toString());
//					}
//				}else if (array==2) {
//					JSONArray jsonArray = parse.getJSONArray(next);
//					System.out.println(next+"\t"+"array"+"\t"+" ");
//					for(int i=0;i<jsonArray.size();i++) {
//						JSONObject jsonObject = jsonArray.getJSONObject(i);
//						System.out.println(next+"\t"+"object"+"\t"+" ");
//						Iterator<String> iterator2 = jsonObject.keySet().iterator();
//						while (iterator2.hasNext()) {
//							String next1 = iterator2.next();
//							Object object1 = jsonObject.get(next1);
//							System.out.println(next1+"\t"+"string"+"\t"+object1==null?"":object1.toString());
//						}
//					}
//				}
//				
//			}
			
			
//			String uuidString = "";
//			String[] keyString = {"补贴类型"};//,"订单状态：已发货 且 线上交易状态：交易关闭"
//			for (int t = 0; t < keyString.length; t++) {
//				String pageString = "ec_accountStatementConversion";
//				String pageString1 = "ec_accountStatementConversionEdit";
//				
//				String pageString2 = "ec_billstatus";
//				
//				//多语设置查询获取
//				String urlString = "https://bip-test.yyuap.com/iuap-apcom-i18n/international-web/location/dev/findByLocationCodeAndContent?productDataSource=YS&categorySource=localCategory";
//				String paramMap = "{\"sourceLang\":\"zh_CN\",\"targetLang\":\"en_US\",\"terminalType\":-1,\"resourceType\":-1,\"resourceSubType\":-1,\"createDate\":{\"value1\":\"\",\"value2\":\"\"},\"modifyDate\":{\"value1\":\"\",\"value2\":\"\"},\"creator\":\"\",\"modifier\":\"\",\"page\":1,\"size\":500,\"isQueryShared\":1,\"pushStatus\":-1,\"caseSensitive\":0,\"isExact\":1,\"locationStatusList\":[-1],\"sourceContent\":\""+keyString[t]+"\",\"categoryId\":\"14b0267f-b24f-4850-bf92-d006a85dd1e9\"}";
//				JSONObject sendPost = JSONObject.parseObject(HttpUtil.sendPost(urlString, paramMap));
//				JSONArray jsonArray = sendPost.getJSONObject("data").getJSONArray("contents");
//				for (int i = 0; i < jsonArray.size(); i++) {
//					String[] locationPath = jsonArray.getJSONObject(i).getString("locationPath").split("/");
//					if (locationPath.length>2 && (locationPath[2].equals(pageString) || locationPath[2].equals(pageString1) || locationPath[2].equals(pageString2))) {
//						if (uuidString.equals("")) {
//							uuidString = jsonArray.getJSONObject(i).getString("locationCode");
//						}else {
//							uuidString = uuidString + "," + jsonArray.getJSONObject(i).getString("locationCode");
//						}
//					}
//				}
//			}
//
//			if (!uuidString.equals("")) {
//				uuidString = uuidString + ",UID:P_SDOC-FE_1971F9BA0420000D";
//			}
//			System.out.println(uuidString);
//			String downurlString = "https://bip-test.yyuap.com/iuap-apcom-migration/script/exportData";
//			
//			String downParaString = "{\"itemKey\":\"iuap-apcom-i18n_newmode_bylocCode\",\"projectName\":\"SDOC\",\"queryInfoList\":[{\"paramName\":\"categoryCode\",\"paramValue\":\"SDOC-UI,SDOC-FE\"},{\"paramName\":\"locationCodeList\",\"paramValue\":\""+uuidString+"\"}],\"profile\":\"基准环境\",\"dbType\":\"MYSQL\"}";
//			
//			HttpUtil.sendFilePost(downurlString, downParaString, "D:\\Program Files\\Desktop\\"+new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())+".zip");
////			System.out.println(uuidString);
			
			
//			String urlString = "https://yonbip-core3.diwork.com/yonbip-mkt-dst/billoperation/doaction?token=bttUi9JQWh2Mm9DOTRrWXlXVExjYmVuKzRQTTdFYXNDZUxFSnRkZ1MrRFRFaTJnTXJwUk5pQk1HVEtXODdPTWkxTl9fZXVjLnlvbnlvdWNsb3VkLmNvbQ..__fc3a101af647ab81de6abef3fed49478_1687934422663dccore3iuap-apcom-workbenchdda6dcb3YT";
//			
//			String paramString = "{\r\n" + 
//					"    \"billnum\": \"ec_trade\",\r\n" + 
//					"    \"action\": \"resendevent\",\r\n" + 
//					"    \"externalData\": \"1761202307080017399543\"\r\n" + 
//					"}";
//			
//			String sendPost = HttpUtil.sendPost(urlString, paramString);
//			System.out.println(sendPost);
			
//		} catch (SecurityException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (FileNotFoundException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} 	
			
		 try {
	            // 加载原始图像文件
	            File input = new File("D:\\Program Files\\Desktop\\ZHANG LIU\\ZHANG LIU\\ZHANG LIU_1.JPG");
	            BufferedImage image = ImageIO.read(input);
	            
	            // 获取图像的Graphics2D对象
	            Graphics2D g2d = (Graphics2D) image.getGraphics();
	            
	            // 设置画笔颜色为红色
	            g2d.setColor(Color.BLACK);
	            
	            String time = new SimpleDateFormat("yyyy/M/d HH:mm").format(new Date());
	            Font font0 = new Font("思源黑体", Font.PLAIN, 16);
	            g2d.setFont(font0);
	            g2d.drawString(time, 50, 45);
	            
	            
	            // 在图像上添加文本
	            String text = "ZHANG LIU";
	            Font font = new Font("思源黑体", Font.PLAIN, 25);
	            g2d.setFont(font);
	            int x = 397;
	            int y = 318;
	            g2d.drawString(text, x, y);
	            

	            
	            int y1 = 355;
	            g2d.drawString("EE0224898", x, y1);
	            
	            int y2 = 411;
	            g2d.drawString("CHINA", x, y2);
	            
	            int y3 = 467;
	            g2d.drawString("03/12/1980", x, y3);
	            
	            int y4 = 504;
	            g2d.drawString("FEMALE", x, y4);
	            
	            int y5 = 543;
	            g2d.drawString("08/08/2028", x, y5);
	            
	            int y6 = 585;
	            g2d.drawString("63185096@qq.com", x, y6);
	            
	            int y7 = 623;
	            g2d.drawString("+8613760602314", x, y7);
	            
	            int y8 = 700;
	            g2d.drawString("08/02/2024", x, y8);
	            
	            int y9 = 740;
	            g2d.drawString("LAND", x, y9);
	            
	            int y10 = 780;
	            g2d.drawString("11/02/2024", x, y10);
	            
	            int y11 = 837;
	            g2d.drawString("SINGAPORE", x, y11);
	            
	            int y12 = 890;
	            g2d.drawString("HOTEL/MOTEL/REST HOUSE", x, y12);
	            
	            int y13 = 930;
	            g2d.drawString("EASTIN HOTEL KUALA LUMPUR", x, y13);
	            
	            int y14 = 975;
	            g2d.drawString("50000", x, y14);
	            
	            int y15 = 1015;
	            g2d.drawString("KUALA LUMPUR", x, y15);
	            
	            int y16 = 1055;
	            g2d.drawString("WP KUALA LUMPUR", x, y16);
	            
	            
	            Font font1 = new Font("思源黑体", Font.ROMAN_BASELINE, 40);
	            g2d.setFont(font1);
	            int y17 = 1150;
	            g2d.drawString("hj9c6qH8", x, y17);
	            
	            
	            
	            String str = "https://wx.mail.qq.com/home/index?sid=zdJRU4xxSXgu0XdPAGAwYQAA#/read/ZL0006_6znNuciMPewuBWUA7W97Ue2";
	            Font font10 = new Font("思源黑体", Font.PLAIN, 16);
	            g2d.setFont(font10);
	            g2d.drawString(str, 50, 1665);
	            
	            
	            // 保存修改后的图像到新文件
	            File output = new File("D:\\Program Files\\Desktop\\ZHANG LIU\\output"+(int)(Math.random()*100)+".jpeg");
	            ImageIO.write(image, "jpeg", output);
	            
	            System.out.println("图像已成功编辑并保存！");
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
		
//		// 设置邮件服务器地址、端口号等信息
//        String host = "imap.163.com";
//        String userName = "travbao@163.com";
//        String password = "DAMZANEUSHOVMBOE";
//        int port = 993;
//        boolean sslEnabled = true;
//        
//        Properties props = new Properties();
////        props.put("mail.pop3.host", host);
//        props.put("mail.imap.host", host);
//        props.put("mail.smtp.auth", "true");
//        props.put("mail.store.protocol", "imaps");
////        props.setProperty("mail.imaps.host", host);
////        props.setProperty("mail.imaps.port", Integer.toString(port));
////        props.setProperty("mail.imaps.ssl.enable", Boolean.toString(sslEnabled));
//        
//        Map<String, String> hashMap = new HashMap();
//        hashMap.put("name", "travbao");
//        hashMap.put("version", "1.0.0");
//        hashMap.put("vendor", "myclient");
//        hashMap.put("support-emial", "travbao@163.com");
//        
//        Session session = Session.getDefaultInstance(props);
//        
//       try {
//    	   // 取得pop3协议的邮件服务器
//    	   IMAPStore store = (IMAPStore)session.getStore("imap");
//    	   // 连接pop.qq.com邮件服务器
//    	   store.connect(userName,password);
//    	   store.id(hashMap);
//    	   //打开收件箱
//    	   Folder folder = store.getFolder("INBOX");
//    	   //设置仅读
//    	   folder.open(Folder.READ_ONLY);
//    	   
//    	   int t =0;
//    	   //读取邮件
//    	   Message[] messages = folder.getMessages();
//    	   for (int i = 0; i < messages.length; i++) {
//			Message message = messages[i];
//			if (message.getSubject().contains("Malaysia Digital Arrival Card")) {
//				
//			}
//			//获取邮件主题
//			System.out.println("--------------"+t+"-----------------");
//			System.out.println("sub:"+message.getSubject());
//			System.out.println("content:"+message.getContent());
//			System.out.println();
//			t+=1;
//		}
//    	   //关闭链接
//    	   folder.close(false);
//    	   store.close();
//	} catch (Exception e) {
//		// TODO: handle exception
//		e.printStackTrace();
//	}
//		
		
//			
		
	}
	
	//简单判断数值是对象还是数组
	public static int isArray(Object object) {
		int t = 0;
		if (object!=null && object.toString().length()>1 && object.toString().substring(0,1).contains("{")) {
			t = 1;
		}else if (object!=null && object.toString().length()>1 && object.toString().substring(0,1).contains("[")) {
			t = 2;
		}
		return t;
	}
	
	
//	   public static void main(String[] args) throws IOException {
//	        String aaString = "Fri Aug 11 18:43:49 GMT+08:00 2023";
//
//            SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", new Locale("ENGLISH","CHINA"));
//			//				Date parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(aaString);
////		        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(parse);
//			try {
//				System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(sdf.parse(aaString)));
//			} catch (ParseException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//			for (int i = 0; i < 10; i++) {
//				System.out.println(UUID.randomUUID());
//			}
//
//	    }
}
